package controller;

import java.io.IOException;

import mainController.ClientController;
import model.AnswerObject;

public class MessageReceiver extends Thread {

	private ClientController clientController;

	public MessageReceiver(ClientController clientController) {
		this.clientController = clientController;
	}
	
	@Override
	public void run() {
		while (true) {
			AnswerObject message = null;
			try {
				message = (AnswerObject) this.clientController.getBufferIn().readObject();
				if (message == null) {
					continue;
				}
			}
			catch (IOException e) {
				System.err.println(e);
				System.exit(1);
			}
			catch (ClassNotFoundException e) {
				System.err.println(e);
				System.exit(1);
			}
			
			this.clientController.receiveMessage(message);
		}
	}
}
